package cn.wizzer.app.web.modules.controllers.platform.user.account;

import cn.wizzer.app.user.modules.services.account.UserAccountService;
import cn.wizzer.framework.page.Pagination;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.math.BigDecimal;

@IocBean
@At("/platform/user/account")
public class AccountController {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private UserAccountService accountService;

    @At("")
    @Ok("beetl:/platform/user/account/index.html")
    @RequiresPermissions("user.account.list")
    public void index() {

    }

    @At
    @Ok("json:full")
    @RequiresPermissions("user.account.list")
    public Object data(@Param("conditionData") String conditionData,
                       @Param("currencyId") String currencyId,
                       @Param("key") String key,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize,
                       @Param("pageOrderName") String pageOrderName,
                       @Param("pageOrderBy") String pageOrderBy) {
        Pagination pagination = accountService.listPage(conditionData, currencyId, key, pageNumber, pageSize, pageOrderName, pageOrderBy);
        // 统计充值总额，根据搜索条件
        BigDecimal sum = accountService.searchSum(conditionData, currencyId, key);
        return Result.success().addData(Result.createMap("pagination", pagination, "sum", sum));
    }


    /**
     * 根据用户id，币种id
     *
     * @param userId
     * @param currencyId
     * @return
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.account.list")
    public Object account(@Param("userId") String userId, @Param("currencyId") String currencyId) {
        return Result.success().addData(accountService.select(userId, currencyId));
    }

}
